import { AutoFight } from "./AutoFight";
import { Language } from "../../../../extend/language/Language";
import { GTextFormat } from "../../../common/GTextFormat";
import { ObjCreate } from "../common/ObjCreate";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { DataProvider } from "../../../../fl/data/DataProvider";
import { OtherThingsSetPanel } from "./OtherThingsSetPanel";
import { GComboBox } from "../../../../com/mui/controls/GComboBox";
import { MailFriendItemCellRender } from "../mail/MailFriendItemCellRender";
import { ResouceConst } from "../../../component/gconst/ResouceConst";
import { ImagesConst } from "../../resource/ImagesConst";
import { GCheckBox } from "../../../../com/mui/controls/GCheckBox";
import { AutoFightInfo } from "./AutoFightInfo";
type int = number;
//class PickAndAcceptPanel
    
    export  class PickAndAcceptPanel /* flash.display.Sprite */
    {
        constructor()
        {
            
            this._pickSelectedEquipMap = new Map<any, any> /* flash.utils.Dictionary */();
            this._pickSelectedCareerMap = new Map<any, any> /* flash.utils.Dictionary */();
            this._pickSelectedDrugMap = new Map<any, any> /* flash.utils.Dictionary */();
            this._autoFightInfo = AutoFight.localAutoFight;
            this._pickSelectedEquipMap[0] = {"id": 0, "label": Language.getString(34031), "index": 0};
            this._pickSelectedEquipMap[2] = {"id": 2, "label": Language.getString(34032), "index": 1};
            this._pickSelectedEquipMap[3] = {"id": 3, "label": Language.getString(34033), "index": 2};
            this._pickSelectedEquipMap[4] = {"id": 4, "label": Language.getString(34034), "index": 3};
            this._pickSelectedCareerMap[0] = {"id": 0, "label": Language.getString(34039), "index": 0};
            this._pickSelectedCareerMap[17] = {"id": 17, "label": Language.getString(31073), "index": 1};
            this._pickSelectedCareerMap[34] = {"id": 34, "label": Language.getString(31074), "index": 2};
            this._pickSelectedCareerMap[68] = {"id": 68, "label": Language.getString(31075), "index": 3};
            this._pickSelectedCareerMap[136] = {"id": 136, "label": Language.getString(31076), "index": 4};
            this._pickSelectedDrugMap[0] = {"id": 0, "label": Language.getString(34049), "index":[]};
            this._pickSelectedDrugMap[1] = {"id": 1, "label": Language.getString(34050), "index":[2, 3]};
            this._pickSelectedDrugMap[2] = {"id": 2, "label": Language.getString(34051), "index":[0, 1]};
            this.init();
            return;
        }

        public resetPanel(arg1: Boolean, arg2: Boolean, arg3: int, arg4: int, arg5: int): void
        {
            var loc1=null;
            var loc2=0;
            this._itemPick.selected = arg1;
            this._itemAccept.selected = arg2;
            if (arg3 != -1) 
            {
                this._itemEquip.selected = true;
                loc1 = this._pickSelectedEquipMap[arg3];
                this._equipCombo.selectedIndex = loc1.index;
                loc1 = this._pickSelectedCareerMap[arg5];
                this._careerComBo.selectedIndex = loc1.index;
            }
            else 
            {
                this._itemEquip.selected = false;
            }
            if (this._itemPick.selected) 
            {
                this._itemEquip.enabled = true;
                this._otherThingsSetPanel.resetOtherThingsPanel();
                if ((loc2 = this._autoFightInfo.pickDrugIdx.length) < 4) 
                {
                    this._itemDrug.selected = true;
                    if (loc2 != 0) 
                    {
                        if (this._autoFightInfo.pickDrugIdx.indexOf(2) == -1) 
                        {
                            this._drugCombo.selectedIndex = 2;
                        }
                        else 
                        {
                            this._drugCombo.selectedIndex = 1;
                        }
                    }
                    else 
                    {
                        this._drugCombo.selectedIndex = 0;
                    }
                }
                else 
                {
                    this._itemDrug.selected = false;
                    this._drugCombo.selectedIndex = 0;
                }
            }
            else 
            {
                this._itemEquip.enabled = false;
                this._itemDrug.enabled = false;
                this._otherThingsSetPanel.itemOtherThings = false;
            }
            return;
        }

        public update(): void
        {
            this.resetPanel(this._autoFightInfo.pickThing, this._autoFightInfo.acceptTeam, this._autoFightInfo.pickEquip, this._autoFightInfo.pickThings, this._autoFightInfo.careerEquip);
            return;
        }

        /* internal  */init(): void
        {
            var loc1=new GTextFormat("", 13, 16776960);
            this._itemPick = ObjCreate.createCheckBox(Language.getString(34004), 20, 10, 160, 20, this, "CheckBoxStyle");
            this._itemPick.setStyle("textFormat", loc1);
            this._itemPick.name = "autoPickSomething";
            this._itemPick.addEventListener(flash.events.Event.CHANGE, this.onAutoPickChangeHandler);
            this._itemAccept = ObjCreate.createCheckBox(Language.getString(34005), 20, 190, 160, 20, this, "CheckBoxStyle");
            this._itemAccept.setStyle("textFormat", loc1);
            this._itemAccept.name = "autoAcceptTeam";
            this._itemAccept.addEventListener(flash.events.Event.CHANGE, this.onAutoAcceptChangeHandler);
            this._itemEquip = ObjCreate.createCheckBox(Language.getString(34044), 20, 40, 160, 20, this, "GCheckBox");
            this._itemEquip.setStyle("textFormat", GlobalStyle.textFormat2);
            this._itemEquip.name = "equipment";
            this._itemEquip.addEventListener(flash.events.Event.CHANGE, this.onItemEquipChangeHandler);
            var loc2=new DataProvider();
            loc2.addItem(this._pickSelectedEquipMap[0]);
            loc2.addItem(this._pickSelectedEquipMap[2]);
            loc2.addItem(this._pickSelectedEquipMap[3]);
            loc2.addItem(this._pickSelectedEquipMap[4]);
            this._equipCombo = this.createComboBox(105, 40, 100, 20, loc2);
            this._equipCombo.addEventListener(flash.events.Event.CHANGE, this.onEquipComboChangeHandler);
            this.addChild(this._equipCombo);
            var loc3=new DataProvider();
            loc3.addItem(this._pickSelectedCareerMap[0]);
            loc3.addItem(this._pickSelectedCareerMap[17]);
            loc3.addItem(this._pickSelectedCareerMap[34]);
            loc3.addItem(this._pickSelectedCareerMap[68]);
            loc3.addItem(this._pickSelectedCareerMap[136]);
            this._careerComBo = this.createComboBox(105, 63, 100, 20, loc3);
            this._careerComBo.addEventListener(flash.events.Event.CHANGE, this.onCareerComboChangeHandler);
            this.addChild(this._careerComBo);
            this._itemDrug = ObjCreate.createCheckBox(Language.getString(34052), 20, 95, 160, 20, this, "GCheckBox");
            this._itemDrug.setStyle("textFormat", GlobalStyle.textFormat2);
            this._itemDrug.addEventListener(flash.events.Event.CHANGE, this.onItemDrugChangeHandler);
            var loc4;
            (loc4 = new DataProvider()).addItem(this._pickSelectedDrugMap[0]);
            loc4.addItem(this._pickSelectedDrugMap[1]);
            loc4.addItem(this._pickSelectedDrugMap[2]);
            this._drugCombo = this.createComboBox(105, 95, 100, 20, loc4);
            this._drugCombo.addEventListener(flash.events.Event.CHANGE, this.onDrugComboChangeHandler);
            addChild(this._drugCombo);
            this._otherThingsSetPanel = new OtherThingsSetPanel();
            this._otherThingsSetPanel.x = 340;
            this._otherThingsSetPanel.y = 43;
            addChild(this._otherThingsSetPanel);
            return;
        }

        /* internal  */createComboBox(arg1: int, arg2: int, arg3: int, arg4: int, arg5: DataProvider): GComboBox
        {
            var loc1;
            (loc1 = new GComboBox()).selectedIndex = 0;
            loc1.width = arg3;
            loc1.height = arg4;
            loc1.move(arg1, arg2);
            loc1.styleName = "GComboboxStyle";
            loc1.drawNow();
            loc1.dropdown.setStyle("cellRenderer", MailFriendItemCellRender);
            loc1.dropdown.setStyle("skin", ResouceConst.getScaleBitmap(ImagesConst.WindowCenterB));
            loc1.textField.setStyle("textFormat", new GTextFormat("", 12, 11661308, false, false, false, "", "", flash.text.TextFormatAlign.CENTER));
            loc1.dataProvider = arg5;
            return loc1;
        }

        /* internal  */onAutoAcceptChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            var loc1=arg1.target as GCheckBox;
            this._autoFightInfo.setAutoFightInfo(loc1.name, loc1.selected);
            this._autoFightInfo.alter = true;
            return;
        }

        /* internal  */onAutoPickChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            var loc1=arg1.target as GCheckBox;
            if (this._itemPick.selected) 
            {
                this._itemEquip.enabled = true;
                this._itemDrug.enabled = true;
                this._itemDrug.selected = true;
                this._autoFightInfo.pickDrugIdx = this._drugCombo.selectedItem.index;
                this._otherThingsSetPanel.itemOtherThings = true;
            }
            else 
            {
                this._itemEquip.enabled = false;
                this._itemDrug.enabled = false;
                this._itemDrug.selected = false;
                this._autoFightInfo.pickDrugIdx = [];
                this._otherThingsSetPanel.itemOtherThings = false;
            }
            this._autoFightInfo.setAutoFightInfo(loc1.name, loc1.selected);
            this._autoFightInfo.alter = true;
            return;
        }

        /* internal  */onEquipComboChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            this._autoFightInfo.pickEquip = this._equipCombo.selectedItem.id;
            this._autoFightInfo.alter = true;
            return;
        }

        /* internal  */onCareerComboChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            this._autoFightInfo.careerEquip = this._careerComBo.selectedItem.id;
            this._autoFightInfo.alter = true;
            return;
        }

        /* internal  */onItemEquipChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            var loc1=arg1.target as GCheckBox;
            if (loc1.selected) 
            {
                this._autoFightInfo.pickEquip = this._equipCombo.selectedItem.id;
                this._autoFightInfo.careerEquip = this._careerComBo.selectedItem.id;
            }
            else 
            {
                this._autoFightInfo.pickEquip = -1;
            }
            this._autoFightInfo.alter = true;
            return;
        }

        /* internal  */onItemDrugChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            if (this._itemDrug.selected) 
            {
                this._autoFightInfo.pickDrugIdx = this._drugCombo.selectedItem.index;
            }
            else 
            {
                this._autoFightInfo.pickDrugIdx = [0, 1, 2, 3];
            }
            this._autoFightInfo.alter = true;
            return;
        }

        /* internal  */onDrugComboChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            if (this._itemDrug.selected) 
            {
                this._autoFightInfo.pickDrugIdx = this._drugCombo.selectedItem.index;
                this._autoFightInfo.alter = true;
            }
            return;
        }

        /* internal */ /* var */_pickSelectedEquipMap: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */_pickSelectedCareerMap: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */_pickSelectedDrugMap: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */_autoFightInfo: AutoFightInfo;

        /* internal */ /* var */_equipCombo: GComboBox;

        /* internal */ /* var */_itemAccept: GCheckBox;

        /* internal */ /* var */_itemEquip: GCheckBox;

        /* internal */ /* var */_itemPick: GCheckBox;

        /* internal */ /* var */_careerComBo: GComboBox;

        /* internal */ /* var */_itemDrug: GCheckBox;

        /* internal */ /* var */_drugCombo: GComboBox;

        /* internal */ /* var */_otherThingsSetPanel: OtherThingsSetPanel;
    }
